package my.mall.admin.api.controller;

import my.mall.admin.api.pojo.dict.DictResp1;
import my.mall.admin.api.service.CacheService;
import my.mall.admin.api.service.DictionaryService;
import my.mall.common.annotation.Slf4j;
import my.mall.common.pojo.CommonResp;
import my.mall.common.util.DateUtils;
import my.mall.common.util.RespUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@Slf4j
public class TestController {

    @Autowired
    private DictionaryService dictionaryService;
    @Autowired
    private CacheService cacheService;

    @GetMapping("test")
    public DictResp1 test(@RequestParam LocalDate time) {
        System.out.println("time: " + DateUtils.INSTANCE.formatLocalDate(time));
        return new DictResp1(1, LocalDate.now(), LocalDateTime.now());
    }

    @PostMapping("test")
    public DictResp1 test(@RequestBody Demo demo) {
        System.out.println("date: " + DateUtils.INSTANCE.formatLocalDateTime(demo.getTime()));
        return new DictResp1(1, LocalDate.now(), LocalDateTime.now());
    }

    public static class Demo {
        private LocalDateTime time;

        public LocalDateTime getTime() {
            return time;
        }

        public void setTime(LocalDateTime time) {
            this.time = time;
        }
    }

    @GetMapping("cache/stats")
    public CommonResp<?> getCacheStats() {
        cacheService.printStatsInfo();
        return RespUtils.INSTANCE.success();
    }
}
